﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using MLBService.Model;

namespace MLBService.Resources
{
    [DataContract]
    public class FranchiseList
    {
        #region Properties

        [DataMember]
        public List<UriLink> Franchises = new List<UriLink>();

        #endregion

        public FranchiseList LoadAll()
        {
            using (fourseamEntities context = new fourseamEntities())
            {
                IEnumerable<Franchise> q = (from f in context.Franchises
                                          orderby f.IsActive descending, f.FranchiseName
                                          select f).ToList<Franchise>();
                foreach (Franchise itm in q)
                {
                    Franchises.Add(new UriLink(Constants.baseUrl + string.Format("franchise/{0}", itm.FranchiseId), itm.FranchiseName));
                }
                return this;
            }
        }


        public FranchiseList LoadCurrent()
        {
            using (fourseamEntities context = new fourseamEntities())
            {
                IEnumerable<Franchise> q = (from f in context.Franchises
                                            where f.IsActive == true
                                            orderby f.IsActive descending, f.FranchiseName
                                            select f).ToList<Franchise>();
                foreach (Franchise itm in q)
                {
                    Franchises.Add(new UriLink(Constants.baseUrl + string.Format("franchise/{0}", itm.FranchiseId), itm.FranchiseName));
                }
                return this;
            }
        }



    }
}